<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>用户中心</title>
  <script type="text/javascript" src="/static/Js/jQuery-3.5.1.js"></script>
  <script type="text/javascript" src="/static/Js/socket.io.js"></script>
  <script type="text/javascript" src="/static/Js/bootstrap/popper.js"></script>
  <script type="text/javascript" src="/static/Js/bootstrap/bootstrap.min.js"></script>
  <script type="text/javascript" src="/static/Js/GetUserParam.js"></script>
  <script type="text/javascript" src="/static/Js/UserFullNameWaterMark.js"></script>
  <script type="text/javascript" src="/static/Js/watermark.js"></script>
  <script type="text/javascript" src="/static/Js/CalculationIsType.js"></script>

  <link rel="stylesheet" href="/static/Css/bootstrap.min.css">
  <link rel="stylesheet" href="/static/Css/CommonStyles.css">
  <link rel="stylesheet" href="/static/Css/TableCommonStyles.css">

</head>
<body id="bg_body" >
<div id="header"></div>
<div class="actionBar" id="actionBar">
  <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="#">用户管理</a></li>
      <li class="breadcrumb-item">
        <div class="btn-group dropright">
          <button type="button" id="dropdown" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">

          </button>
          <div class="dropdown-menu" id="dropdown-menu">

          </div>
        </div>
      </li>
    </ol>
  </nav>
</div>

<script>
  function getUserManageCenterNav() {
    $.post("/userFusion/getUserManageCenterSideBar",{},function (result) {
      if (result.flag) {
        let i = 0
        for (const resultElement of result.data) {
          let element = document.createElement("div")
          element.className = "menuSpan"
          element.setAttribute("id",resultElement.htmlid)
          element.setAttribute("onclick",resultElement.fun)
          element.innerHTML = resultElement.context
          let parentElement = document.getElementById("dropdown-menu")
          parentElement.appendChild(element)
          if (i === 0) {
            if (resultElement.umid === 1) {
              usermanageCount1(element)

            }else if (resultElement.umid === 2) {
              usermanageCount2(element)

            }
          }
         i++

        }

      }else {

      }
    })
  }

  function usermanageCount1(obj){
    TopPage = 1
    document.getElementById("dropdown").innerHTML = document.getElementById(obj.id).innerHTML
    getAllUserData(TopPage)
  }
  function usermanageCount2(obj){
    TopPage = 1
    document.getElementById("dropdown").innerHTML = document.getElementById(obj.id).innerHTML
    getAllRole(TopPage)

  }


  let TopPage
  $(function () {
    TopPage = 1
    getUserManageCenterNav()
    UserFullNameWaterMark()

  })
  function getPageUrl() {
    return window.location.pathname
  }
  $.get('./HeadPage.html',function(data){
    $("#header").html(data)
  })
  $.get("./Toasts.html",function (data){
    $("#ToastsPage").html(data)
  })

  function getAllRole(page){
    let thArr = []

    thArr.push("角色")
    thArr.push("权限")
    thArr.push("授权账号")
    thArr.push("操作")

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","searchBarBtn()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "条件查找"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_input2 = document.createElement("input")
    searchBar_Div_nav_ol_li_input2.className = "form-control searchBarInput"
    searchBar_Div_nav_ol_li_input2.setAttribute("type","text")
    searchBar_Div_nav_ol_li_input2.setAttribute("id","searchBarInput")
    searchBar_Div_nav_ol_li_input2.setAttribute("placeholder","查找账号")

    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_input2)


    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)
    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    $.post("/userFusion/getAllRole",{page:page},function (result){
      setTable(searchBar_Div,thArr,result,4)
    })

  }

  function getAllUserData(page) {
    URoleS = []
    let thArr = []
    thArr.push("ID")
    thArr.push("账号")
    thArr.push("真实姓名")
    thArr.push("账号状态")
    thArr.push("归属")
    thArr.push("认证状态")
    thArr.push("角色")
    thArr.push("操作")

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","searchBarBtn()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "条件查找"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_input2 = document.createElement("input")
    searchBar_Div_nav_ol_li_input2.className = "form-control searchBarInput"
    searchBar_Div_nav_ol_li_input2.setAttribute("type","text")
    searchBar_Div_nav_ol_li_input2.setAttribute("id","searchBarInput")
    searchBar_Div_nav_ol_li_input2.setAttribute("placeholder","查找账号")

    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_input2)






    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)
    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)




    $.post("/userFusion/getAllUserData",{page:page},function (result){

        setTable(searchBar_Div,thArr,result,1)


    })
  }

  function setTable(searchBar_Div,thArr,result,tableType){
    $("#context").remove()
    $("#pageBar_nav").remove()
    $("#searchBar").remove()
    $("#errBar").remove()



    /*errBar*/
    let errBar_Div = document.createElement("div")
    errBar_Div.setAttribute("id","errBar")
    errBar_Div.className = "errBar"
    errBar_Div.innerHTML = "占位"
    errBar_Div.style.visibility = "hidden"
    if (!result.flag){
      errBar_Div.innerText = result.errorMsg
      errBar_Div.style.visibility = "visible"
    }
    document.getElementById("bg_body").appendChild(searchBar_Div)
    document.getElementById("bg_body").appendChild(errBar_Div)


    let pageBar_nav = document.createElement("nav")
    pageBar_nav.setAttribute("aria-label","Page navigation example")
    pageBar_nav.className = "pageBar_nav"
    pageBar_nav.setAttribute("id","pageBar_nav")

    let pageBar_ul = document.createElement("ul")
    pageBar_ul.setAttribute("class","pagination")

    if (result.data.current === 1 || result.data.current < 0) {
      let pageBar_ul_li1 = document.createElement("li")
      pageBar_ul_li1.className = "page-item disabled "

      let pageBar_ul_li_a1 = document.createElement("a")
      pageBar_ul_li_a1.className = "page-link"
      pageBar_ul_li_a1.setAttribute("href","#")
      pageBar_ul_li_a1.setAttribute("aria-label","Previous")

      let pageBar_ul_li_a_span1 = document.createElement("span")
      pageBar_ul_li_a_span1.setAttribute("aria-hidden","true")
      pageBar_ul_li_a_span1.innerHTML = "&laquo;"

      pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
      pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
      pageBar_ul.appendChild(pageBar_ul_li1)
    }else {
      let pageBar_ul_li1 = document.createElement("li")
      pageBar_ul_li1.className = "page-item"
      pageBar_ul_li1.setAttribute("onclick","gotoPage("+1+","+tableType+")")

      let pageBar_ul_li_a1 = document.createElement("a")
      pageBar_ul_li_a1.className = "page-link"
      pageBar_ul_li_a1.setAttribute("href","#")
      pageBar_ul_li_a1.setAttribute("aria-label","Previous")

      let pageBar_ul_li_a_span1 = document.createElement("span")
      pageBar_ul_li_a_span1.setAttribute("aria-hidden","true")
      pageBar_ul_li_a_span1.innerHTML = "&laquo;"

      pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
      pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
      pageBar_ul.appendChild(pageBar_ul_li1)
    }



    for (let i = 0; i < result.data.pages; i++) {
      if (result.data.current === (i+1)){
        let pageBar_ul_li = document.createElement("li")
        pageBar_ul_li.className = "page-item active"

        let pageBar_ul_li_a = document.createElement("a")
        pageBar_ul_li_a.className = "page-link"
        pageBar_ul_li_a.setAttribute("href","#")
        pageBar_ul_li_a.innerHTML = (i+1)
        pageBar_ul_li.appendChild(pageBar_ul_li_a)
        pageBar_ul.appendChild(pageBar_ul_li)
      }else {
        let pageBar_ul_li = document.createElement("li")
        pageBar_ul_li.className = "page-item"
        pageBar_ul_li.setAttribute("onclick","gotoPage("+(i+1)+","+tableType+")")
        let pageBar_ul_li_a = document.createElement("a")
        pageBar_ul_li_a.className = "page-link"
        pageBar_ul_li_a.setAttribute("href","#")
        pageBar_ul_li_a.innerHTML = (i+1)
        pageBar_ul_li.appendChild(pageBar_ul_li_a)
        pageBar_ul.appendChild(pageBar_ul_li)
      }

    }
    let pageBar_ul_li2
    let pageBar_ul_li_a2
    let pageBar_ul_li_a_span2
    if (result.data.current === result.data.pages || result.data.current > result.data.pages) {
      pageBar_ul_li2 = document.createElement("li")
      pageBar_ul_li2.className = "page-item disabled"

      pageBar_ul_li_a2 = document.createElement("a")
      pageBar_ul_li_a2.className = "page-link"
      pageBar_ul_li_a2.setAttribute("href","#")
      pageBar_ul_li_a2.setAttribute("aria-label","Next")

      pageBar_ul_li_a_span2 = document.createElement("span")
      pageBar_ul_li_a_span2.setAttribute("aria-hidden","true")
      pageBar_ul_li_a_span2.innerHTML = "&raquo;"
    }else {
      pageBar_ul_li2 = document.createElement("li")
      pageBar_ul_li2.className = "page-item"
      pageBar_ul_li2.setAttribute("onclick","gotoPage("+result.data.pages+","+tableType+")")
      pageBar_ul_li_a2 = document.createElement("a")
      pageBar_ul_li_a2.className = "page-link"
      pageBar_ul_li_a2.setAttribute("href","#")
      pageBar_ul_li_a2.setAttribute("aria-label","Next")

      pageBar_ul_li_a_span2 = document.createElement("span")
      pageBar_ul_li_a_span2.setAttribute("aria-hidden","true")
      pageBar_ul_li_a_span2.innerHTML = "&raquo;"

    }


    let contextSpan = document.createElement("span")
    contextSpan.innerHTML = "共计"+ result.data.total +"条数据"
    contextSpan.className = "contextSpan"



    pageBar_ul_li_a2.appendChild(pageBar_ul_li_a_span2)
    pageBar_ul_li2.appendChild(pageBar_ul_li_a2)
    pageBar_ul.appendChild(pageBar_ul_li2)
    pageBar_ul.appendChild(contextSpan)



    let tableEle = document.createElement("table")
    tableEle.setAttribute("id","pointTable")
    let theadEle = document.createElement("thead")
    let theadTr = document.createElement("tr")

    let contextDiv = document.createElement("div")
    contextDiv.setAttribute("id","context")

    let thEle_select = document.createElement("th")
    thEle_select.setAttribute("id","ALLCustomSwitchTh")



    let select_div_th = document.createElement("div")
    select_div_th.className = "custom-control custom-switch"



    let select_input_th = document.createElement("input")
    select_input_th.setAttribute("type","checkbox")
    select_input_th.className = "custom-control-input"
    select_input_th.setAttribute("id","ALLCustomSwitch")
    select_input_th.setAttribute("onclick","ALLCustomSwitch(this)")

    let select_label_th = document.createElement("label")
    select_label_th.className = "custom-control-label"
    select_label_th.setAttribute("for","ALLCustomSwitch")
    select_label_th.innerHTML = "全选"

    select_div_th.appendChild(select_input_th)
    select_div_th.appendChild(select_label_th)
    thEle_select.appendChild(select_div_th)
    theadTr.appendChild(thEle_select)
    for (const thArrElement of thArr) {
      let thEle = document.createElement("th")
      thEle.innerHTML = thArrElement
      theadTr.appendChild(thEle)
    }
    let flag;
    theadEle.appendChild(theadTr)
    tableEle.appendChild(theadEle)
    let tbody1 = document.createElement("tbody")
    let tbody;

    switch (tableType){
      case 1: tbody = setAllUserTd(tbody1,result)
            break;
      case 2:tbody = setViewURoles(tbody1,result)
              flag = tableType
            break;
      case 3:tbody = setAllocationRole(tbody1,result)
            break;
      case 4:tbody = setAllRole(tbody1,result)
            break;
      case 5:tbody = setViewUser(tbody1,result)
            break;
      case 6:tbody = setViewPermission(tbody1,result)
            break;

    }


    tableEle.appendChild(tbody)
    contextDiv.appendChild(tableEle)
    pageBar_nav.appendChild(pageBar_ul)


    document.getElementById("bg_body").appendChild(contextDiv)
    document.getElementById("bg_body").appendChild(pageBar_nav)

    switch (flag){
      case 2:document.getElementById("ALLCustomSwitchTh").style.display = "none"
            break;
    }

  }
  function setAllRole(tbody,result) {
    let index = 0
    for (const datum of result.data.records) {
      index++

      let tbodyTr = document.createElement("tr")

      let trTd_select = document.createElement("td")

      let select_div = document.createElement("div")
      select_div.className = "custom-control custom-switch"

      let select_input = document.createElement("input")
      select_input.setAttribute("type","checkbox")
      select_input.className = "custom-control-input"
      select_input.setAttribute("name",index)
      select_input.setAttribute("id","customSwitch"+index)

      let select_label = document.createElement("label")
      select_label.className = "custom-control-label"
      select_label.setAttribute("for","customSwitch"+index)

      select_div.appendChild(select_input)
      select_div.appendChild(select_label)
      trTd_select.appendChild(select_div)




      let trTd_role = document.createElement("td")
      trTd_role.setAttribute("id","role"+index)
      trTd_role.innerHTML = datum.alias
      trTd_role.setAttribute("ondblclick","roleEdit(this,"+index+")")

      let trTd_permissionCount = document.createElement("td")
      if (datum.permissionCount > 0) {
        let trTd_permissionCount_a = document.createElement("a")
        trTd_permissionCount_a.innerHTML = datum.permissionCount + "项"
        trTd_permissionCount_a.setAttribute("onclick","viewPermission("+index+","+result.data.current+",\""+datum.alias+"\")")
        trTd_permissionCount_a.setAttribute("id","permissionCount"+index)
        trTd_permissionCount.appendChild(trTd_permissionCount_a)

        trTd_permissionCount_a.style.color = "#666"
        trTd_permissionCount_a.className = "DailyEle"
      }



      let trTd_userCont = document.createElement("td")
      if (datum.userCont > 0 ){
        let trTd_userCont_a = document.createElement("a")
        trTd_userCont_a.setAttribute("onclick","viewUser("+index+","+result.data.current+",\""+datum.alias+"\")")
        trTd_userCont_a.innerHTML = datum.userCont + "个"
        trTd_userCont_a.setAttribute("id","userCont"+index)
        trTd_userCont.appendChild(trTd_userCont_a)

        trTd_userCont_a.style.color = "#666"
        trTd_userCont_a.className = "DailyEle"

      }




      let trTd_action = document.createElement("td")
      let trDailyEle = document.createElement("a")
      trDailyEle.innerHTML = "详细"
      trDailyEle.className = "DailyEle"
      trDailyEle.style.display = "none"
      trDailyEle.setAttribute("id","DailyEle" + index)
      trDailyEle.setAttribute("onclick","DailyEle("+index+")")

      let trDeleteEle = document.createElement("a")
      trDeleteEle.innerHTML = "删除"
      trDeleteEle.className = "DeleteEle"
      trDeleteEle.style.display = "none"
      trDeleteEle.setAttribute("id","trDeleteEle" + index)
      trDeleteEle.setAttribute("onclick","DeleteEle("+index+")")








      trTd_action.appendChild(trDailyEle)
      trTd_action.appendChild(trDeleteEle)



      tbodyTr.appendChild(trTd_select)
      tbodyTr.appendChild(trTd_role)
      tbodyTr.appendChild(trTd_permissionCount)
      tbodyTr.appendChild(trTd_userCont)
      tbodyTr.appendChild(trTd_action)


      tbody.appendChild(tbodyTr)

    }
    return tbody;
  }

  function setAllUserTd(tbody,result) {
    let index = 0
    for (const datum of result.data.records) {
      index++



      let tbodyTr = document.createElement("tr")

      let trTd_select = document.createElement("td")

      let select_div = document.createElement("div")
      select_div.className = "custom-control custom-switch"

      let select_input = document.createElement("input")
      select_input.setAttribute("type","checkbox")
      select_input.className = "custom-control-input"
      select_input.setAttribute("name",index)
      select_input.setAttribute("id","customSwitch"+index)

      let select_label = document.createElement("label")
      select_label.className = "custom-control-label"
      select_label.setAttribute("for","customSwitch"+index)

      select_div.appendChild(select_input)
      select_div.appendChild(select_label)
      trTd_select.appendChild(select_div)

      let trTd_ID = document.createElement("td")
      trTd_ID.innerHTML = index


      let trTd_groupId = document.createElement("td")
      trTd_groupId.setAttribute("id","groupID"+index)
      trTd_groupId.innerHTML = groupType(datum.groupId)
      trTd_groupId.setAttribute("ondblclick","groupIdEdit(this,"+index+")")


      let trTd_fullName = document.createElement("td")
      trTd_fullName.innerHTML = datum.fullname
      trTd_fullName.setAttribute("id","fullName"+index)

      let trTd_uname = document.createElement("td")
      trTd_uname.innerHTML = datum.uname
      trTd_uname.setAttribute("id","uname"+index)

      let status = GetUserDeleteStatus();
      let userDeleteStatus = document.createElement("td")

      for (const status1 of status) {
        if (status1.status === datum.deletestatus){

          userDeleteStatus.innerHTML = status1.alias
        }
      }
      userDeleteStatus.setAttribute("id","userDeleteStatus"+index)
      userDeleteStatus.setAttribute("ondblclick","setUserDeleteStatus("+index+")")


      let sysAuthentication = document.createElement("td")
      if (datum.sysAuthentication === "YES"){
        sysAuthentication.innerHTML = "认证成功"
      }else {
        sysAuthentication.innerHTML = "未认证"
      }
      sysAuthentication.setAttribute("id","sysAuthentication"+index)

      let trTd_role = document.createElement("td")
      let trTd_role_a = document.createElement("a")

      if (datum.uroleCount > 0) {
        trTd_role_a.innerHTML = datum.uroleCount+"项"
        trTd_role_a.setAttribute("id","viewURoles" + index)
        trTd_role_a.setAttribute("onclick","viewURoles("+index+","+result.data.current+")")
      }

      trTd_role_a.style.color = "#666"
      trTd_role_a.className = "DailyEle"


      trTd_role.appendChild(trTd_role_a)


      let allocationRole = document.createElement("td")
      let trDailyEle_allocationRole = document.createElement("a")
      trDailyEle_allocationRole.setAttribute("id","allocationRole" + index)
      if (datum.sysAuthentication === "YES"){
        trDailyEle_allocationRole.innerHTML = "分配角色"
        trDailyEle_allocationRole.className = "DailyEle"

        trDailyEle_allocationRole.setAttribute("onclick","allocationRole("+index+","+1+")")
      }
      allocationRole.appendChild(trDailyEle_allocationRole)


      let trDailyEle = document.createElement("a")
      trDailyEle.innerHTML = "详细"
      trDailyEle.className = "DailyEle"
      trDailyEle.style.display = "none"
      trDailyEle.setAttribute("id","DailyEle" + index)
      trDailyEle.setAttribute("onclick","DailyEle("+index+")")

      let trDeleteEle = document.createElement("a")
      trDeleteEle.innerHTML = "删除"
      trDeleteEle.className = "DeleteEle"
      trDeleteEle.style.display = "none"
      trDeleteEle.setAttribute("id","trDeleteEle" + index)
      trDeleteEle.setAttribute("onclick","DeleteEle("+index+")")

      allocationRole.appendChild(trDailyEle)
      allocationRole.appendChild(trDeleteEle)







      tbodyTr.appendChild(trTd_select)
      tbodyTr.appendChild(trTd_ID)
      tbodyTr.appendChild(trTd_uname)
      tbodyTr.appendChild(trTd_fullName)
      tbodyTr.appendChild(userDeleteStatus)
      tbodyTr.appendChild(trTd_groupId)
      tbodyTr.appendChild(sysAuthentication)
      tbodyTr.appendChild(trTd_role)
      tbodyTr.appendChild(allocationRole)
      tbody.appendChild(tbodyTr)


    }
    return tbody;
  }
  let URoleS

  function gotoPage(page,tableType) {
    TopPage = page
    switch (tableType){
      case 1:getAllUserData(page);
        break;
      case 2:viewURoles(viewURoles_TopIndex,page);
        break;
      case 3:allocationRole(viewURoles_TopIndex,page);
        break;
      case 4:getAllRole(page);
        break;
      case 5:viewUser(viewUser_TopIndex,page,viewUser_role);
        break;
      case 6:viewPermission(viewPermission_TopIndex,page,viewUser_role);
        break;
    }

  }
  let userDeleteStatusContext
  let userDeleteStatusEdit
  function setUserDeleteStatus(index) {
    trDeleteEle_cancel(index)
    userDeleteStatusContext = ""
    userDeleteStatusEdit = ""
    Edit_index = ""
    Edit_index = index

    userDeleteStatusEdit = document.getElementById("userDeleteStatus"+index)
    userDeleteStatusContext = document.getElementById("userDeleteStatus"+index).innerText
    userDeleteStatusEdit.innerText = ""
    userDeleteStatusEdit.style.textAlign = "left"

    let status = GetUserDeleteStatus();
    let i = 0
    for (const groupElement of status) {
      i++
      let select_input_th = document.createElement("input")
      select_input_th.setAttribute("type", "radio")
      select_input_th.setAttribute("name", "userDeleteStatus")
      select_input_th.setAttribute("value",groupElement.status)
      select_input_th.className = "editInput"
      select_input_th.setAttribute("id", "userDeleteStatus"+i)
      if (i === 1) {
        select_input_th.setAttribute("checked","")
      }

      let select_label_th = document.createElement("label")
      select_label_th.className = "editLabel"
      select_label_th.innerHTML = groupElement.alias
      let br = document.createElement("br")

      userDeleteStatusEdit.appendChild(select_input_th)
      userDeleteStatusEdit.appendChild(select_label_th)
      userDeleteStatusEdit.appendChild(br)
    }


    let allocationRole = document.getElementById("allocationRole"+index)
    let DailyEleBtn = document.getElementById("DailyEle"+index)
    let trDeleteEle = document.getElementById("trDeleteEle"+index)
    trDeleteEle.style.display = "inline"
    DailyEleBtn.style.display = "inline"
    allocationRole.style.display = "none"
    DailyEleBtn.innerText = "确定"
    trDeleteEle.innerText = "取消"
    DailyEleBtn.setAttribute("onclick","userDeleteStatusDailyEleBtn_ok("+index+")")
    trDeleteEle.setAttribute("onclick","trDeleteEle_cancel("+index+")")


  }

  function trDeleteEle_cancel(index) {

    if (userDeleteStatusEdit !== undefined && userDeleteStatusEdit !== ""){
      $("#"+userDeleteStatusEdit.id).empty()
      userDeleteStatusEdit.innerText = userDeleteStatusContext
      userDeleteStatusEdit.style.textAlign = "center"

    }

    if (groupIdEdit_td !== undefined && groupIdEdit_td !== "") {
      $("#"+groupIdEdit_td.id).empty()
      groupIdEdit_td.innerText = tdText
      groupIdEdit_td.style.textAlign = "center"

    }
    let allocationRole = $("[id^='allocationRole']")
    let DailyEleBtn = $("[id^='DailyEle']")
    let trDeleteEle = $("[id^='trDeleteEle']")
    let i = 0
    for (const allocationRoleElement of allocationRole) {
      i++
      allocationRoleElement.style.display = "inline"
    }
    for (const dailyEleBtnElement of DailyEleBtn) {
      i++
      dailyEleBtnElement.style.display = "none"

    }
    for (const trDeleteEleElement of trDeleteEle) {
      i++
      trDeleteEleElement.style.display = "none"


    }


  }

  function setAllocationRole(tbody,result) {
    let index = 0
    for (const datum of result.data.records) {
      index++

      let tbodyTr = document.createElement("tr")

      let trTd_select = document.createElement("td")

      let select_div = document.createElement("div")
      select_div.className = "custom-control custom-switch"

      let select_input = document.createElement("input")
      select_input.setAttribute("type","checkbox")
      select_input.setAttribute("value","1")
      select_input.className = "custom-control-input"
      select_input.setAttribute("name",index)
      select_input.setAttribute("id","customSwitch"+index)

      let select_label = document.createElement("label")
      select_label.className = "custom-control-label"
      select_label.setAttribute("for","customSwitch"+index)

      select_div.appendChild(select_input)
      select_div.appendChild(select_label)
      trTd_select.appendChild(select_div)

      for (const resultElement of result.data2) {
        if (datum.uroleId === resultElement.uroleId){
          select_input.setAttribute("checked","")
          select_input.setAttribute("value","2")
        }
      }

      let trTd_uRole = document.createElement("td")
      trTd_uRole.innerHTML = datum.alias
      trTd_uRole.setAttribute("id","uRole"+index)

      let trTd_uname = document.createElement("td")
      trTd_uname.innerHTML = viewURoles_uname
      trTd_uname.setAttribute("id","uname"+index)

      tbodyTr.appendChild(trTd_select)
      tbodyTr.appendChild(trTd_uRole)
      tbodyTr.appendChild(trTd_uname)

      tbody.appendChild(tbodyTr)

    }
    return tbody;
  }

  let tdText;
  let groupIdEdit_td;
  let Edit_index
  function groupIdEdit(obj,index) {

    trDeleteEle_cancel(index)
    Edit_index = ""
    Edit_index = index

    tdText=""
    groupIdEdit_td = ""

    groupIdEdit_td = document.getElementById(obj.id)
alert(groupIdEdit_td.innerText)
    tdText = groupIdEdit_td.innerText
    groupIdEdit_td.innerText = ""
    groupIdEdit_td.style.textAlign = "left"

    let allocationRole = document.getElementById("allocationRole"+index)
    let DailyEleBtn = document.getElementById("DailyEle"+index)
    let trDeleteEle = document.getElementById("trDeleteEle"+index)
    trDeleteEle.style.display = "inline"
    DailyEleBtn.style.display = "inline"
    allocationRole.style.display = "none"
    DailyEleBtn.innerText = "确定"
    trDeleteEle.innerText = "取消"
    DailyEleBtn.setAttribute("onclick","groupDailyEleBtn_ok("+index+")")
    trDeleteEle.setAttribute("onclick","trDeleteEle_cancel("+index+")")



    let group = GetGroup();
    let i = 0
    for (const groupElement of group) {
      i++
      let select_input_th = document.createElement("input")
      select_input_th.setAttribute("type", "radio")
      select_input_th.setAttribute("name","editInput")
      select_input_th.setAttribute("value",groupElement.groupContext)
      select_input_th.className = "editInput"
      select_input_th.setAttribute("id", "editInput"+i)

      let select_label_th = document.createElement("label")
      select_label_th.className = "editLabel"
      select_label_th.innerHTML = groupElement.groupAlias
      let br = document.createElement("br")
      if (tdText === groupElement.groupAlias){
        select_input_th.setAttribute("checked", "")
      }

      groupIdEdit_td.appendChild(select_input_th)
      groupIdEdit_td.appendChild(select_label_th)
      groupIdEdit_td.appendChild(br)
    }
  }

  function groupDailyEleBtn_ok(index) {
    let editInput = $("[id^='editInput']")
    let uname = document.getElementById("uname"+index).innerText
    let group = ""
    for (const groupElement of editInput) {
      if ($(groupElement).is(":checked") === true) {
        group = groupElement.value
      }
    }
    $.ajax({
      url:"/userFusion/setUserGroup",
      type:"post",
      dataType:"json",
      data:{uname:uname,group:group},
      async:false,
      success:function (result) {
        setErrMsgBar(result.errorMsg,result.flag)
      },
      complete:function (){
        getAllUserData(TopPage)
      }
    })
  }

  function userDeleteStatusDailyEleBtn_ok(index) {
    let userDeleteStatus = $("[id^='userDeleteStatus']")
    let uname = document.getElementById("uname"+index).innerText
    let userDeleteStatusValue = ""
    for (const userDeleteStatus1 of userDeleteStatus) {
      if ($(userDeleteStatus1).is(":checked") === true) {
        userDeleteStatusValue = userDeleteStatus1.value
      }
    }

    $.ajax({
      url:"/userFusion/setUserDeleteStatus",
      type:"post",
      dataType:"json",
      data:{uname:uname,userDeleteStatusValue:userDeleteStatusValue},
      async:false,
      success:function (result) {
        setErrMsgBar(result.errorMsg,result.flag)
      },
      complete:function (){
         getAllUserData(TopPage)
      }
    })

  }
  function setErrMsgBar(errMsg,flag) {
    if (flag){
      document.getElementById("errBar").innerText = errMsg
      document.getElementById("errBar").style.visibility = "visible"
    }else {
      document.getElementById("errBar").style.visibility = "hidden"
    }

  }
  let viewURoles_uname
  let viewURoles_fullname
  let viewURoles_userStatus
  let viewURoles_TopIndex
  function viewURoles(index,page) {
    viewURoles_TopIndex = index
    viewURoles_uname = ''
    viewURoles_fullname = ''
    viewURoles_userStatus = ''

    viewURoles_uname = document.getElementById("uname"+index).innerText
    viewURoles_fullname = document.getElementById("fullName"+index).innerText
    viewURoles_userStatus = document.getElementById("userDeleteStatus"+index).innerText
    let thArr = []
    thArr.push("角色")
    thArr.push("账号")
    thArr.push("真实姓名")
    thArr.push("账号状态")



    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","userAllTableBack()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "返回"


    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)

    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)

    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    $.post("/userFusion/viewURoles",{page:page,uname:viewURoles_uname},function (result) {
      setTable(searchBar_Div,thArr,result,2)
    })


  }
  let viewPermission_TopIndex
  function viewPermission(index,page,role){
    let thArr = []
    viewUser_role = role
    thArr.push("权限")
    thArr.push("角色")

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","roleAllTableBack()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "返回"

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button2 = document.createElement("button")
    searchBar_Div_nav_ol_li_button2.className = "btn btn-success searchBarBtn"
    searchBar_Div_nav_ol_li_button2.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button2.setAttribute("onclick","setDeleteRolePermissionBtn("+index+",\""+page+"\",\""+role+"\")")
    searchBar_Div_nav_ol_li_button2.innerHTML = "确定"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)
    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_button2)



    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)

    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    $.post("/userFusion/viewPermission",{page:page,role:role},function (result) {
      setTable(searchBar_Div,thArr,result,6)
    })
  }

  function setViewPermission(tbody,result){
    let index = 0;
    let role_td


    for (const datum of result.data.records) {
      index++
      let tbodyTr = document.createElement("tr")
      let trTd_select = document.createElement("td")

      let select_div = document.createElement("div")
      select_div.className = "custom-control custom-switch"

      let select_input = document.createElement("input")
      select_input.setAttribute("type","checkbox")
      select_input.className = "custom-control-input"
      select_input.setAttribute("name",index)
      select_input.setAttribute("id","customSwitch"+index)

      let select_label = document.createElement("label")
      select_label.className = "custom-control-label"
      select_label.setAttribute("for","customSwitch"+index)

      select_div.appendChild(select_input)
      select_div.appendChild(select_label)
      trTd_select.appendChild(select_div)
      tbodyTr.appendChild(trTd_select)

      for (const datum2Element of result.data2) {
        if (datum2Element.uppermissionId === datum.permissionId){
          select_input.setAttribute("checked","")
        }
      }









      let trTd_permission = document.createElement("td")
      trTd_permission.setAttribute("id","permission"+index)


      tbodyTr.appendChild(trTd_permission)

      trTd_permission.innerHTML = datum.permissionContext


      if (index === 1) {
        let trTd_role = document.createElement("td")
        trTd_role.innerHTML =viewUser_role
        trTd_role.setAttribute("id","viewUser_role"+index)

        tbodyTr.appendChild(trTd_role)
        role_td = trTd_role
      }




      tbody.appendChild(tbodyTr)

    }
    role_td.rowSpan = index


    return tbody;
  }


let viewUser_role;
  let viewUser_TopIndex
  function viewUser(index,page,role){
    let thArr = []
    viewUser_TopIndex = index
    viewUser_role = role
    thArr.push("账号")
    thArr.push("真实姓名")
    thArr.push("角色")



    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","roleAllTableBack()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "返回"

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button2 = document.createElement("button")
    searchBar_Div_nav_ol_li_button2.className = "btn btn-success searchBarBtn"
    searchBar_Div_nav_ol_li_button2.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button2.setAttribute("onclick","setRoleUserBtn("+index+",\""+page+"\",\""+role+"\")")
    searchBar_Div_nav_ol_li_button2.innerHTML = "确定"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)
    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_button2)



    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)

    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    $.post("/userFusion/viewUser",{page:page,role:role},function (result) {
      setTable(searchBar_Div,thArr,result,5)
    })

  }

  function setViewUser(tbody,result) {
    let index = 0;
    let role_td


    for (const datum of result.data.records) {
    index++
    let tbodyTr = document.createElement("tr")


      let trTd_select = document.createElement("td")

      let select_div = document.createElement("div")
      select_div.className = "custom-control custom-switch"

      let select_input = document.createElement("input")
      select_input.setAttribute("type","checkbox")
      select_input.setAttribute("checked","")
      select_input.className = "custom-control-input"
      select_input.setAttribute("name",index)
      select_input.setAttribute("id","customSwitch"+index)

      let select_label = document.createElement("label")
      select_label.className = "custom-control-label"
      select_label.setAttribute("for","customSwitch"+index)

      select_div.appendChild(select_input)
      select_div.appendChild(select_label)
      trTd_select.appendChild(select_div)
      tbodyTr.appendChild(trTd_select)



    let trTd_uname = document.createElement("td")
    trTd_uname.setAttribute("id","uname"+index)

    let trTd_fullName = document.createElement("td")
    trTd_fullName.setAttribute("id","fullName"+index)

      tbodyTr.appendChild(trTd_uname)
      tbodyTr.appendChild(trTd_fullName)

    trTd_uname.innerHTML = datum.uname
    trTd_fullName.innerHTML = datum.fullname

      if (index === 1) {
        let trTd_role = document.createElement("td")
        trTd_role.innerHTML =viewUser_role
        trTd_role.setAttribute("id","viewUser_role"+index)

        tbodyTr.appendChild(trTd_role)
        role_td = trTd_role
      }




    tbody.appendChild(tbodyTr)

  }
  role_td.rowSpan = index


  return tbody;
  }

  function setViewURoles(tbody,result) {

    let index = 0
    let uname;
    let fullName;
    let deleteStatus;


    for (const datum of result.data.records) {
      index++
      let tbodyTr = document.createElement("tr")

      let trTd_role = document.createElement("td")
      trTd_role.innerHTML =datum.alias
      trTd_role.setAttribute("id","alias"+index)

      tbodyTr.appendChild(trTd_role)

      if (index === 1) {
        let trTd_uname = document.createElement("td")
        trTd_uname.setAttribute("id","uname"+index)

        let trTd_fullName = document.createElement("td")
        trTd_fullName.setAttribute("id","fullName"+index)

        let userDeleteStatus = document.createElement("td")
        userDeleteStatus.innerHTML = viewURoles_userStatus

        userDeleteStatus.setAttribute("id","userDeleteStatus"+index)

        trTd_uname.innerHTML = viewURoles_uname
        trTd_fullName.innerHTML = viewURoles_fullname

        uname = trTd_uname
        fullName = trTd_fullName
        deleteStatus = userDeleteStatus
        tbodyTr.appendChild(userDeleteStatus)
        tbodyTr.appendChild(trTd_uname)
        tbodyTr.appendChild(trTd_fullName)


      }

      tbody.appendChild(tbodyTr)

    }
    uname.rowSpan = index
    fullName.rowSpan = index
    deleteStatus.rowSpan = index

    return tbody;
  }
  function userAllTableBack() {
    getAllUserData(TopPage)
  }

  let allocationRole_TopIndex
  function allocationRole(index,page) {
    allocationRole_TopIndex = index
    viewURoles_uname = ''

    viewURoles_uname = document.getElementById("uname"+index).innerText

    let thArr = []


    thArr.push("角色")
    thArr.push("账号")

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","userAllTableBack()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "返回"

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button2 = document.createElement("button")
    searchBar_Div_nav_ol_li_button2.className = "btn btn-success searchBarBtn"
    searchBar_Div_nav_ol_li_button2.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button2.setAttribute("onclick","userRole_ok("+index+")")
    searchBar_Div_nav_ol_li_button2.innerHTML = "确定"


    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)
    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_button2)

    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)

    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    $.post("/userFusion/findAllUserRole",{page:page,uname:viewURoles_uname},function (result) {
      setTable(searchBar_Div,thArr,result,3)
    })

  }

  function ALLCustomSwitch(obj) {
    let arr_customSwitch = $("[id^='customSwitch']")
    let dailyS = $("[id^='DailyEle']")
    let DailyReviseEleS = $("[id^='DailyReviseEle']")
    if ($(obj).is(":checked") === true) {
      for (const daily of dailyS) {
        document.getElementById(daily.id).style.visibility = "hidden"
      }
      for (const dailyReviseEle of DailyReviseEleS) {
        document.getElementById(dailyReviseEle.id).style.visibility = "hidden"
      }
      for (const arrCustomSwitch of arr_customSwitch) {

        $("#"+arrCustomSwitch.id).prop("checked", true)
      }
    }else {
      for (const arrCustomSwitch of arr_customSwitch) {
        $("#"+arrCustomSwitch.id).prop("checked", false)
      }
      for (const daily of dailyS) {
        document.getElementById(daily.id).style.visibility = "visible"
      }
      for (const dailyReviseEle of DailyReviseEleS) {
        document.getElementById(dailyReviseEle.id).style.visibility = "visible"
      }
    }
  }

  function userRole_ok(index){
    let arr_customSwitch = $("[id^='customSwitch']")
    let arr_uRole = $("[id^='uRole']")
    let roleStatusArr = []
    let roleContext = []
    for (const arrCustomSwitch of arr_customSwitch) {

      if ($(arrCustomSwitch).is(":checked") === true) {
        roleStatusArr.push(2)
      }else {
        roleStatusArr.push(1)
      }

    }
    for (const arrURoleElement of arr_uRole) {
      roleContext.push(document.getElementById(arrURoleElement.id).innerText)
    }
    $.post("/userFusion/allocationRole",{roleContext:JSON.stringify(roleContext),roleStatusArr:JSON.stringify(roleStatusArr),uname:viewURoles_uname},function (result){
          setErrMsgBar(result.errorMsg,result.flag)
      setTimeout(function (){
        allocationRole(index)
      },2000)

    })
  }

  function roleAllTableBack() {
    getAllRole(1)
  }

  function setRoleUserBtn(index,page,role) {
    let arr_customSwitch = $("[id^='customSwitch']")
    let unameArr= []
    for (const arrCustomSwitch of arr_customSwitch) {
      if ($(arrCustomSwitch).is(":checked") !== true) {
        let index = arrCustomSwitch.name
        unameArr.push(document.getElementById("uname"+index).innerText)
      }
    }

    $.ajax({
      url:"/userFusion/setRoleDeleteUser",
      type:"post",
      dataType:"json",
      async:false,
      data:{unameArr:JSON.stringify(unameArr),role:role},
      complete:function () {
        viewUser(index,page,role)
      }
    })

  }

  function setDeleteRolePermissionBtn(index,page,role){
    let arr_customSwitch = $("[id^='customSwitch']")
    let permissionArr= []
    let authArr = []
    let authTemplateArr = []
    for (const arrCustomSwitch of arr_customSwitch) {
      if ($(arrCustomSwitch).is(":checked") === true) {
        let index = arrCustomSwitch.name
        authArr.push(document.getElementById("permission"+index).innerText)
    }
    }

    for (const arrCustomSwitch of arr_customSwitch) {
        let index = arrCustomSwitch.name
      authTemplateArr.push(document.getElementById("permission"+index).innerText)
    }
    $.ajax({
      url:"/userFusion/setDeleteRolePermissionBtn",
      type:"post",
      dataType:"json",
      async:false,
      data:{role:role,authArr:JSON.stringify(authArr),authTemplateArr:JSON.stringify(authTemplateArr)},
      complete:function () {
        viewPermission(index,page,role)
      }
    })

  }


</script>
</body>
</html>